package com.yunquan.ohana.base.ui

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.yunquan.ohana.base.bus.event.SingleLiveEvent


class UIChangeLiveData : SingleLiveEvent<Any>() {
    var showDialogEvent: SingleLiveEvent<String>? = null
        get() = createLiveData(field).also { field = it }
        private set

    var dismissDialogEvent: SingleLiveEvent<Void>? = null
        get() = createLiveData(field).also { field = it }
        private set

    var startActivityEvent: SingleLiveEvent<Map<String, Any>>? = null
        get() = createLiveData(field).also {
            field = it
        }
        private set

    var startActivityForResultEvent: SingleLiveEvent<Map<String, Any>>? = null
        get() = createLiveData(field).also {
            field = it
        }
        private set


    var finishEvent: SingleLiveEvent<Void>? = null
        get() {
            return createLiveData(field).also { field = it }
        }
        private set

    var onBackPressedEvent: SingleLiveEvent<Void>? = null
        get() {
            return createLiveData(field).also { field = it }
        }
        private set

    private fun <T : Any> createLiveData(liveData: SingleLiveEvent<T>?): SingleLiveEvent<T> {
        var liveData2: SingleLiveEvent<T>? = liveData
        if (liveData2 == null) {
            liveData2 = SingleLiveEvent()
        }
        return liveData2
    }

    override fun observe(owner: LifecycleOwner, observer: Observer<in Any?>) {
        super.observe((owner), observer)
    }
}